﻿package com.daz.common.inquire.action;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import ch.qos.logback.core.joran.conditional.Condition;

import com.alibaba.fastjson.JSON;
import com.daz.common.inquire.pojo.Inquire;
import com.daz.common.inquire.server.IInquireServer;
import com.daz.common.publicDict.pojo.publicDictPojo;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class InquireAction extends ActionSupport{
	@Autowired
	private IInquireServer inquireServer;
	public Boolean success;
	public String dels;
	public String jsonString;
	public List<Inquire> inquireList;
	public String inquireCode;
	public String addInquire(){
		Inquire inquire = JSON.parseObject(jsonString, Inquire.class);
		try {
			this.setSuccess(inquireServer.addInquire(inquire));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	public String updateInquire(){
		Inquire inquire = JSON.parseObject(jsonString, Inquire.class);
		try {
			this.setSuccess(inquireServer.updateInquire(inquire));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	public String selectInquire(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("inquireCode", inquireCode);
		try {
			inquireList = inquireServer.searchInquires(map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	public String delectInquire(){
		String[] delsStrings = dels.split(",");
		List<String> delList = new ArrayList<>();
		Collections.addAll(delList, delsStrings);
		try {
			this.setSuccess(inquireServer.deleteInquire(delList));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	public Boolean getSuccess() {
		return success;
	}
	public void setSuccess(Boolean success) {
		this.success = success;
	}
	public String getDels() {
		return dels;
	}
	public void setDels(String dels) {
		this.dels = dels;
	}
	public String getJsonString() {
		return jsonString;
	}
	public void setJsonString(String jsonString) {
		this.jsonString = jsonString;
	}
	public List<Inquire> getInquireList() {
		return inquireList;
	}
	public void setInquireList(List<Inquire> inquireList) {
		this.inquireList = inquireList;
	}
	public String getInquireCode() {
		return inquireCode;
	}
	public void setInquireCode(String inquireCode) {
		this.inquireCode = inquireCode;
	}
	
}
